package com.qsw.refreshrecyclerview.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.qsw.refreshrecyclerview.R;
import com.qsw.refreshrecyclerview.RefreshRecyclerView.adapter.RefreshRecyclerViewAdapter;
import com.qsw.refreshrecyclerview.RefreshRecyclerView.view.GridSpacingItemDecoration;
import com.qsw.refreshrecyclerview.RefreshRecyclerView.view.RefreshRecyclerView;

import java.util.ArrayList;
import java.util.List;

public class RRVTestGridActivity extends Activity {

    private RefreshRecyclerView rrv;

    private LinearLayoutManager mLinearLayoutManager;
    private RecyclerView.ItemDecoration mItemDecoration;
    private RefreshRecyclerViewAdapter mTestRcvAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rrv_activity_test);

        TextView tv = findViewById(R.id.btn);
        tv.setText("跳转");
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(RRVTestGridActivity.this, RRVOtherActivity.class));
            }
        });

        rrv = findViewById(R.id.rrvl_rrv);
        mLinearLayoutManager = new GridLayoutManager(this, 3);
        rrv.setLayoutManager(mLinearLayoutManager);
        mItemDecoration = new GridSpacingItemDecoration(1, 0, 3, 12, 20);
        rrv.setItemSpace(mItemDecoration);
    }

    @Override
    protected void onStart() {
        super.onStart();
        List<String> data = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            data.add(String.valueOf(i));
        }
        mTestRcvAdapter = new RRVTestRecyclerViewGridAdapter(data, 3);

        rrv.setAdapter(mTestRcvAdapter);
        View header = LayoutInflater.from(this).inflate(R.layout.rrv_test_header, rrv, false);
        rrv.addHeaderView(header);

        rrv.recoverLastPosition();
    }

    @Override
    protected void onStop() {
        super.onStop();

        rrv.recordCurrPosition();
    }
}
